/** 
 * File-Name:AppAction.java
 *
 * Created on 2011-6-3 下午04:43:58
 * 
 * @author: Neo (neolimeng@gmail.com)
 * Software Engineering Institute, Peking University, China
 * 
 * Copyright (c) 2009, Peking University
 * 
 *
 */
package site.web;

import java.util.List;

import neoutil.CommonAction;

import org.apache.log4j.Logger;

import site.entity.Article;
import site.entity.Category;
import site.entity.User;
import site.service.repository.ArticleRepository;

/**
 * Description:
 * 
 * @author: Neo (neolimeng@gmail.com) Software Engineering Institute, Peking
 *          University, China
 * @version 1.0 2011-6-3 下午04:43:58
 */
public class AppAction extends CommonAction {
	private static Logger log = Logger.getLogger(AppAction.class);
	private List<Article> latestNotices;
	private List<Article> latestNews;
	private List<Article> latestHeadNews;
	private List<Article> latestNews1;
	private List<Article> latestNews2;
	private List<Article> latestNews3;
	private List<Article> latestNews4;
	private List<Article> latestNews5;

	public String toHome() {
		try {
			/**
			 * 首页最新“通知公告”
			 */
			ArticleRepository articleRepository = new ArticleRepository();
			latestNotices = articleRepository.getLatestArticlesByCid(
					Category.LATEST_NOTICE, 6);
			latestHeadNews = articleRepository.getLatestArticlesByCid(
					Category.HEAD_NEWS, 5);
			System.out.println("Latest Head News Size:: "
					+ latestHeadNews.size());

			/**
			 * 首页“工作动态”
			 */
			latestNews = articleRepository.getLatestArticlesByCid(
					Category.LATEST_NEWS, 5);

			latestNews1 = articleRepository.getLatestArticlesByCid(
					Category.HYZX, 5);

			latestNews2 = articleRepository.getLatestArticlesByCid(
					Category.QYFC, 5);

			latestNews3 = articleRepository.getLatestArticlesByCid(
					Category.JSHZ, 5);

			latestNews4 = articleRepository.getLatestArticlesByCid(
					Category.ZSYZ, 5);

			latestNews5 = articleRepository.getLatestArticlesByCid(
					Category.JSPX, 5);

			return SUCCESS;
		} catch (Exception e) {
			e.printStackTrace();
			return INPUT;
		}
	}

	public String toManageHome() {
		try {
			User user = (User) getSessionObject("loginUser");
			if (user == null) {
				log.error("用户未登录！");
				return RELOGIN;
			} else {
				return SUCCESS;
			}
		} catch (Exception e) {
			e.printStackTrace();
			return INPUT;
		}
	}

	public String to() {
		return SUCCESS;
	}

	// Getters and Setters
	public List<Article> getLatestNotices() {
		return latestNotices;
	}

	public void setLatestNotices(List<Article> latestNotices) {
		this.latestNotices = latestNotices;
	}

	public List<Article> getLatestNews() {
		return latestNews;
	}

	public void setLatestNews(List<Article> latestNews) {
		this.latestNews = latestNews;
	}

	public List<Article> getLatestHeadNews() {
		return latestHeadNews;
	}

	public void setLatestHeadNews(List<Article> latestHeadNews) {
		this.latestHeadNews = latestHeadNews;
	}

	public List<Article> getLatestNews1() {
		return latestNews1;
	}

	public void setLatestNews1(List<Article> latestNews1) {
		this.latestNews1 = latestNews1;
	}

	public List<Article> getLatestNews2() {
		return latestNews2;
	}

	public void setLatestNews2(List<Article> latestNews2) {
		this.latestNews2 = latestNews2;
	}

	public List<Article> getLatestNews3() {
		return latestNews3;
	}

	public void setLatestNews3(List<Article> latestNews3) {
		this.latestNews3 = latestNews3;
	}

	public List<Article> getLatestNews4() {
		return latestNews4;
	}

	public void setLatestNews4(List<Article> latestNews4) {
		this.latestNews4 = latestNews4;
	}

	public List<Article> getLatestNews5() {
		return latestNews5;
	}

	public void setLatestNews5(List<Article> latestNews5) {
		this.latestNews5 = latestNews5;
	}

}
